{extend name="layout:layout" /}

{block name="title"}Excel导入/导出{/block}

{block name="stylesheet"}
<link type="text/css" rel="stylesheet" href="/static/bootstrap/css/bootstrap.min.css">
{/block}

{block name="body"}
<div style="padding: 15px;">
    <div class="panel panel-success">
        <div class="panel-heading">Excel导出</div>
        <div class="panel-body">
            <a href="{:url('Always/export')}" class="layui-btn layui-btn-xs">导出Excel</a>
        </div>
    </div>
    <div class="panel panel-info">
        <div class="panel-heading">Excel导入</div>
        <div class="panel-body">
            <form class="layui-form" target="importFrame" action="{:url('Always/import')}" enctype="multipart/form-data"
                  method="post">
                <div class="row">
                    <div class="col-xs-3">
                        <div class="form-group">
                            <input type="file" name="excel" id="excel_01" lay-verify="excel_01" lay-verType="tips">
                        </div>
                    </div>
                    <div class="col-xs-2">
                        <div class="form-group">
                            <button type="submit" class="btn btn-primary" lay-submit lay-filter="importSubmit">
                                <span class="glyphicon glyphicon-ok"></span> 导入数据
                            </button>
                        </div>
                    </div>
                </div>
            </form>
            <iframe name="importFrame" style="width: 100%;height: 400px;border: 1px solid #dadada;"></iframe>
        </div>
    </div>
</div>
{/block}
{block name="javascript"}
<script type="text/javascript" src="/static/bt_filestyle/bootstrap-filestyle.js"></script>
<script type="text/javascript">
    function uploadMsg(msg) {
        layui.use(['layer'], function () {
            layer.msg(msg, {anim: 1});
        });
    }
    $('#excel_01').filestyle({
        buttonText: ' 选择Excel文件',
        buttonName: 'btn-warning'
    });
    layui.use(['element','form'], function () {
        var form  = layui.form;
        //验证是否选择文件
        form.verify({
            excel_01: function (value, item) {
                if (value.length == 0) {
                    return '请选择Excel文件!';
                }
            }
        });
        //Form表单提交
        form.on('submit(importSubmit)', function (data) {
            //{id:id}不能去掉，去掉了后后台无法接收文件
            $.post(data.form.action, {id: id}, function (obj) {
            })
            return false;
        });
    });
</script>
{/block}